package cn.stylefeng.guns.sys.modular.system.service;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.modular.system.entity.BtyArchives;
import cn.stylefeng.guns.sys.modular.system.entity.BtyShopTree;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyArchivesMapper;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyShopTreeMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 档案管理表 服务实现类
 * </p>
 *
 * @author liuy
 * @since
 */
@Service
public class BtyArchivesService extends ServiceImpl<BtyArchivesMapper, BtyArchives> {
    @Resource
    private BtyShopTreeMapper btyShopTreeMapper;

    /**
     * 获取档案管理列表
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:05 PM
     */

    public Page<Map<String, Object>> list(String condition,String dm,String tel,String month,String status) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.list(page, condition,dm,tel,month,status);
    }

    /**
     * 设置区域人员的openid
     */
    public  int setOpenid(String openid,String xm,String yhk){
        return this.baseMapper.setOpenid(openid,xm,yhk);
    }

    /**
     * 写入三级区域
     */
    public void insertShop() {
        //获取所有的二级区域
        List<String> secondNameList = baseMapper.getSecondShop();

        int num = 16;

        //获取对应二级区域下面的三级区域
        for (String secondName : secondNameList) {

            //获取bty_shop_name表中对应的二级区域
            BtyShopTree secondShop = btyShopTreeMapper.getBySimpleName(secondName);

            //获取二级区域下的三级区域
            List<String> thirdShopList = baseMapper.getNextShop(secondName);
            BtyShopTree shopSave = new BtyShopTree();
            //将获取到的三级区域插入表中
            for (String thirdName : thirdShopList) {
                num = num + 1;
                shopSave.setShopId(Long.valueOf(num));
                shopSave.setPid(secondShop.getShopId());
                //pids
                shopSave.setPids(secondShop.getPids() + "[" + secondShop.getShopId() + "]");
                shopSave.setSimpleName(thirdName);
                shopSave.setFullName(thirdName);
                shopSave.setCreateTime(new Date());
                btyShopTreeMapper.insert(shopSave);
            }

        }
    }

    /**
     * 写入四级区域-门店
     */
    public void  insertMenDian(){
        //获得所有的店
        List<BtyArchives> allShop = baseMapper.getAllShop();
        int num = 65;

        BtyShopTree shopSave = new BtyShopTree();
        for(BtyArchives shop:allShop){
            num = num + 1;
            //获取bty_shop_name表中三级区域中与店对应的父级区域
            BtyShopTree fuShop = btyShopTreeMapper.getThirdShopBySimpleName(shop.getEqy());
            shopSave.setShopId(Long.valueOf(num));
            shopSave.setPid(fuShop.getShopId());
            //pids
            shopSave.setPids(fuShop.getPids() + "[" + fuShop.getShopId() + "]");
            shopSave.setSimpleName(shop.getDm());
            shopSave.setFullName(shop.getDm());
            shopSave.setCreateTime(new Date());
            btyShopTreeMapper.insert(shopSave);
        }

        System.out.println("一共店有"+allShop.size()+"条");
    }


    /**
     * 获取所有银行卡
     * @return
     */
    public List getYhk() {
        return baseMapper.getYHK();
    }

    public Page<Map<String, Object>> listYhk(String xm, String tel, String dm, String yhkStatus) {
        Page page = LayuiPageFactory.defaultPage();
        return baseMapper.listYhk(page,xm, tel, dm, yhkStatus);
    }

    public Map getBank(String hh) {
        return baseMapper.getBank(hh);
    }

    //各银行简称及其对应名称
    public Map<String, String> cardUtil(){

        Map<String, String> map = new HashMap<>();
        map.put("SRCB","深圳农村商业银行");
        map.put("BGB","广西北部湾银行");
        map.put("SHRCB","上海农村商业银行");
        map.put("BJBANK","北京银行");
        map.put("WHCCB","威海市商业银行");
        map.put("BOZK","周口银行");
        map.put("KORLABANK","库尔勒市商业银行");
        map.put("SPABANK","平安银行");
        map.put("SDEB","顺德农商银行");
        map.put("HURCB","湖北省农村信用社");
        map.put("WRCB","无锡农村商业银行");
        map.put("BOCY","朝阳银行");
        map.put("CZBANK","浙商银行");
        map.put("HDBANK","邯郸银行");
        map.put("BOC","中国银行");
        map.put("BOD","东莞银行");
        map.put("CCB","中国建设银行");
        map.put("ZYCBANK","遵义市商业银行");
        map.put("SXCB","绍兴银行");
        map.put("GZRCU","贵州省农村信用社");
        map.put("ZJKCCB","张家口市商业银行");
        map.put("BOJZ","锦州银行");
        map.put("BOP","平顶山银行");
        map.put("HKB","汉口银行");
        map.put("SPDB","上海浦东发展银行");
        map.put("NXRCU","宁夏黄河农村商业银行");
        map.put("NYNB","广东南粤银行");
        map.put("GRCB","广州农商银行");
        map.put("BOSZ","苏州银行");
        map.put("HZCB","杭州银行");
        map.put("HSBK","衡水银行");
        map.put("HBC","湖北银行");
        map.put("JXBANK","嘉兴银行");
        map.put("HRXJB","华融湘江银行");
        map.put("BODD","丹东银行");
        map.put("AYCB","安阳银行");
        map.put("EGBANK","恒丰银行");
        map.put("CDB","国家开发银行");
        map.put("TCRCB","江苏太仓农村商业银行");
        map.put("NJCB","南京银行");
        map.put("ZZBANK","郑州银行");
        map.put("DYCB","德阳商业银行");
        map.put("YBCCB","宜宾市商业银行");
        map.put("SCRCU","四川省农村信用");
        map.put("KLB","昆仑银行");
        map.put("LSBANK","莱商银行");
        map.put("YDRCB","尧都农商行");
        map.put("CCQTGB","重庆三峡银行");
        map.put("FDB","富滇银行");
        map.put("JSRCU","江苏省农村信用联合社");
        map.put("JNBANK","济宁银行");
        map.put("CMB","招商银行");
        map.put("JINCHB","晋城银行");
        map.put("FXCB","阜新银行");
        map.put("WHRCB","武汉农村商业银行");
        map.put("HBYCBANK","湖北银行宜昌分行");
        map.put("TZCB","台州银行");
        map.put("TACCB","泰安市商业银行");
        map.put("XCYH","许昌银行");
        map.put("CEB","中国光大银行");
        map.put("NXBANK","宁夏银行");
        map.put("HSBANK","徽商银行");
        map.put("JJBANK","九江银行");
        map.put("NHQS","农信银清算中心");
        map.put("MTBANK","浙江民泰商业银行");
        map.put("LANGFB","廊坊银行");
        map.put("ASCB","鞍山银行");
        map.put("KSRB","昆山农村商业银行");
        map.put("YXCCB","玉溪市商业银行");
        map.put("DLB","大连银行");
        map.put("DRCBCL","东莞农村商业银行");
        map.put("GCB","广州银行");
        map.put("NBBANK","宁波银行");
        map.put("BOYK","营口银行");
        map.put("SXRCCU","陕西信合");
        map.put("GLBANK","桂林银行");
        map.put("BOQH","青海银行");
        map.put("CDRCB","成都农商银行");
        map.put("QDCCB","青岛银行");
        map.put("HKBEA","东亚银行");
        map.put("HBHSBANK","湖北银行黄石分行");
        map.put("WZCB","温州银行");
        map.put("TRCB","天津农商银行");
        map.put("QLBANK","齐鲁银行");
        map.put("GDRCC","广东省农村信用社联合社");
        map.put("ZJTLCB","浙江泰隆商业银行");
        map.put("GZB","赣州银行");
        map.put("GYCB","贵阳市商业银行");
        map.put("CQBANK","重庆银行");
        map.put("DAQINGB","龙江银行");
        map.put("CGNB","南充市商业银行");
        map.put("SCCB","三门峡银行");
        map.put("CSRCB","常熟农村商业银行");
        map.put("SHBANK","上海银行");
        map.put("JLBANK","吉林银行");
        map.put("CZRCB","常州农村信用联社");
        map.put("BANKWF","潍坊银行");
        map.put("ZRCBANK","张家港农村商业银行");
        map.put("FJHXBC","福建海峡银行");
        map.put("ZJNX","浙江省农村信用社联合社");
        map.put("LZYH","兰州银行");
        map.put("JSB","晋商银行");
        map.put("BOHAIB","渤海银行");
        map.put("CZCB","浙江稠州商业银行");
        map.put("YQCCB","阳泉银行");
        map.put("SJBANK","盛京银行");
        map.put("XABANK","西安银行");
        map.put("BSB","包商银行");
        map.put("JSBANK","江苏银行");
        map.put("FSCB","抚顺银行");
        map.put("HNRCU","河南省农村信用");
        map.put("COMM","交通银行");
        map.put("XTB","邢台银行");
        map.put("CITIC","中信银行");
        map.put("HXBANK","华夏银行");
        map.put("HNRCC","湖南省农村信用社");
        map.put("DYCCB","东营市商业银行");
        map.put("ORBANK","鄂尔多斯银行");
        map.put("BJRCB","北京农村商业银行");
        map.put("XYBANK","信阳银行");
        map.put("ZGCCB","自贡市商业银行");
        map.put("CDCB","成都银行");
        map.put("HANABANK","韩亚银行");
        map.put("CMBC","中国民生银行");
        map.put("LYBANK","洛阳银行");
        map.put("GDB","广东发展银行");
        map.put("ZBCB","齐商银行");
        map.put("CBKF","开封市商业银行");
        map.put("H3CB","内蒙古银行");
        map.put("CIB","兴业银行");
        map.put("CRCBANK","重庆农村商业银行");
        map.put("SZSBK","石嘴山银行");
        map.put("DZBANK","德州银行");
        map.put("SRBANK","上饶银行");
        map.put("SRBANK","上饶银行");
        map.put("JXRCU","江西省农村信用");
        map.put("ICBC","中国工商银行");
        map.put("JZBANK","晋中市商业银行");
        map.put("HZCCB","湖州市商业银行");
        map.put("NHB","南海农村信用联社");
        map.put("XXBANK","新乡银行");
        map.put("JRCB","江苏江阴农村商业银行");
        map.put("YNRCC","云南省农村信用社");
        map.put("ABC","中国农业银行");
        map.put("GXRCU","广西省农村信用");
        map.put("PSBC","中国邮政储蓄银行");
        map.put("BZMD","驻马店银行");
        map.put("ARCU","安徽省农村信用社");
        map.put("GSRCU","甘肃省农村信用");
        map.put("LYCB","辽阳市商业银行");
        map.put("JLRCU","吉林农信");
        map.put("URMQCCB","乌鲁木齐市商业银行");
        map.put("XLBANK","中山小榄村镇银行");
        map.put("CSCB","长沙银行");
        map.put("JHBANK","金华银行");
        map.put("BHB","河北银行");
        map.put("NBYZ","鄞州银行");
        map.put("LSBC","临商银行");
        map.put("BOCD","承德银行");
        map.put("SDRCU","山东农信");
        map.put("NCB","南昌银行");
        map.put("TCCB","天津银行");
        map.put("WJRCB","吴江农商银行");
        map.put("CBBQS","城市商业银行资金清算中心");
        map.put("HBRCU","河北省农村信用社");
        map.put("LNRCC","辽宁省农村信用社");
        map.put("FJNX","福建省农村信用社");
        map.put("ZYB","中原银行");
        return map;
    }


    public List<Map> export(String yhkStatus) {
        List<Map> list = baseMapper.exportList(yhkStatus);
        return list;

    }

    public List<String> dmList() {
        List<String> list = baseMapper.dmList();
        return list;
    }

    public List<Map> yyjlList() {
        List<Map> list = baseMapper.yyjlList();
        return list;
    }

    public List<Map> ddList(String yyjl) {
        List<Map> list = baseMapper.ddList(yyjl);
        return list;
    }

    public void updateYhk(BtyArchives btyArchives) {
        //银行名称
        String cardName = cardUtil().get(btyArchives.getBank());
        btyArchives.setCardName(cardName);
        baseMapper.updateYhk(btyArchives);
    }

    public String getYhkByBh(String bh) {
        return baseMapper.getYhkByBh(bh);
    }
}
